package com.itany.controller;

import com.itany.pojo.Manager;
import com.itany.service.ManagerService;
import com.itany.vo.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Description: 类的描述
 * Author: SJY
 * Date: 2021/09/01 16:03
 * Version: 1.0 版本信息
 */
@Controller
@RequestMapping("/manageruser")
public class ManagerController {
    @Autowired
    ManagerService managerService;

    @RequestMapping("/login")
    public ModelAndView selectLogin(HttpServletRequest request, HttpServletResponse response){
        ModelAndView mv = new ModelAndView();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if(username==null && username=="" && password==null && password==""){
            mv.addObject("msg","请正确填写帐号密码");
        }
        mv.setViewName("redirect:/manager/login");
        Manager manager = new Manager();
        manager.setUsername(username);
        manager.setPassword(password);
        ActionResult ar = managerService.selectLogin(manager);
        if (ar.getData()!=null){
            request.getSession().setAttribute("user",ar.getData());
            mv.setViewName("redirect:/manager/index");
        }
        return mv;
    }
}
